Skip to content

feat(virtual): derive visibleCount and overscan from container size#13

Open
chiefcll wants to merge 1 commit into
mainfrom
virtual-derived-sizing
Open

feat(virtual): derive visibleCount and overscan from container size#13
chiefcll wants to merge 1 commit into
mainfrom
virtual-derived-sizing

Conversation

@chiefcll
Copy link
Copy Markdown
Contributor

Summary

Replaces VirtualRow / VirtualColumn with a version that derives window size from the rendered layout instead of asking the caller for it. The outer API is otherwise unchanged.

Removed props (all auto-derived now):

Removed Replacement
displaySize floor(container size / (first child size + gap))
bufferSize max(2, ceil(visibleCount * 0.25))
uniformSize always treated as uniform (was the default)
factorScale dropped; layout uses unscaled item size

All other props (each, wrap, scrollIndex, onEndReached, onEndReachedThreshold, debugInfo, children, plus inherited scroll/selected/onSelectedChanged) are unchanged. VirtualGrid is untouched.

How it works

  • On mount, a single probe item is rendered so the layout pass has something to measure.
  • After the first updateLayout() the container's width/height and the first child's size are read; visibleCount, bufferSize, and itemSize are cached in a single signal.
  • Once measurement completes, the full slice is rendered and the existing computeSlice state machine takes over — all the scroll / wrap / edge logic from before is preserved verbatim.
  • Item size is assumed uniform for the lifetime of the component. Callers swapping to a differently-sized dataset should remount.

Caller-facing behavior change

  • Callers must give the Virtual element a measurable width (Row) or height (Column) on first layout — either explicit, or sized by a flex parent. If the container has no size on the first measurement attempt, the effect re-runs when each updates.
  • First paint shows one probe item; the full window appears on the next microtask.

Test plan

  • npm run tsc — clean
  • npm run lint — 0 errors (warnings are pre-existing)
  • npm test — 120/120 passing
  • Smoke-test a real app with VirtualRow and VirtualColumn to confirm one-frame measurement is imperceptible and scroll behavior matches v1
  • Verify wrap, scrollIndex, and scroll: 'edge' | 'always' | 'auto' modes still behave as before

🤖 Generated with Claude Code

Removes displaySize, bufferSize, uniformSize, and factorScale props
from VirtualRow / VirtualColumn. Visible count and buffer are now
computed from container width/height and the first child's measured
size on a single layout pass; the result is cached for the lifetime
of the component (item size assumed uniform).

A single probe item is rendered until measurement completes, then the
full slice expands in. Container must have a measurable width (Row)
or height (Column) on first layout.

VirtualGrid is untouched.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@chiefcll chiefcll force-pushed the virtual-derived-sizing branch from 494bf14 to dbd9595 Compare May 17, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant